/**
 * Created by SJG on 2017/12/19.
 */
$(function () {
    $("#formSignIn").submit(function (event) {
        $.ajax({
            url: "/toLogin",
            type: "POST",
            data: JSON.stringify($(this).serializeObject()),
            headers: {
                Accept: "application/json;charset=utf-8"
            },
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            success: function (data) {
                alert("登录成功")
            },
            error:function (jqXHR) {
                var contentType = jqXHR.getResponseHeader("Content-Type");
                if (jqXHR.status === 200 && contentType.toLowerCase().indexOf("text/html") >= 0) {
                    location.href="/";
                    return;
                }
                $("#divError").html("登录失败！").removeClass("hidden");
            }
        });

        event.preventDefault();
    });
});